var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
define(["require", "exports", "react", "maishu-dilu", "maishu-ui-toolkit", "../services/local-service", "../config"], function (require, exports, React, maishu_dilu_1, maishu_ui_toolkit_1, local_service_1, config_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    const USERNAME = "username";
    const PASSWORD = "password";
    const LOGIN = "login";
    class LoginPage extends React.Component {
        constructor(props) {
            super(props);
            this.state = {
                buttonText: '发送验证码', buttonEnable: true
            };
        }
        login() {
            return __awaiter(this, void 0, void 0, function* () {
                let service = this.props.createService(local_service_1.LocalService);
                let { username, password } = this.state;
                let r = yield service.login(username, password);
                let target = config_1.config.loginRedirectURL || "index";
                this.props.app.redirect(target);
            });
        }
        componentDidMount() {
            this.validator = new maishu_dilu_1.FormValidator(this.element, { name: USERNAME, rules: [maishu_dilu_1.rules.required('请输入用户名')] }, { name: PASSWORD, rules: [maishu_dilu_1.rules.required('请输入密码')] });
        }
        render() {
            let { username, password } = this.state;
            return React.createElement(React.Fragment, null,
                React.createElement("h1", { key: 8, className: "text-center", style: { paddingBottom: 50 } }, "\u597D\u6613\u5FAE\u5546\u57CE\u5546\u6237\u540E\u53F0"),
                React.createElement("div", { key: 10, className: "form-horizontal container", style: { maxWidth: 500 }, ref: (e) => this.element = e || this.element },
                    React.createElement("div", { className: "form-group" },
                        React.createElement("label", { className: "col-sm-2 control-label" }, "\u7528\u6237\u540D"),
                        React.createElement("div", { className: "col-sm-10" },
                            React.createElement("input", { name: USERNAME, type: "text", className: "form-control", value: username || '', onChange: e => {
                                    this.setState({ username: e.target.value });
                                } }))),
                    React.createElement("div", { className: "form-group" },
                        React.createElement("label", { className: "col-sm-2 control-label" }, "\u5BC6\u7801"),
                        React.createElement("div", { className: "col-sm-10" },
                            React.createElement("input", { type: "password", name: PASSWORD, className: "form-control", value: password || '', onChange: e => {
                                    this.setState({ password: e.target.value });
                                } }))),
                    React.createElement("div", { className: "form-group" },
                        React.createElement("div", { className: "col-sm-offset-2 col-sm-10" },
                            React.createElement("button", { name: LOGIN, type: "button", className: "btn btn-primary btn-block", ref: e => {
                                    if (!e)
                                        return;
                                    maishu_ui_toolkit_1.buttonOnClick(e, () => this.login());
                                } },
                                React.createElement("i", { className: "icon-key" }),
                                "\u7ACB\u5373\u767B\u5F55"))),
                    React.createElement("div", { className: "form-group" },
                        React.createElement("div", { className: "col-sm-offset-2 col-sm-10" },
                            React.createElement("div", { className: "pull-left" },
                                React.createElement("button", { name: "forget-password", className: "btn-link", onClick: () => this.props.app.redirect("forget-password") }, "\u5FD8\u8BB0\u5BC6\u7801")),
                            React.createElement("div", { className: "pull-right" },
                                React.createElement("button", { name: "register", className: "btn-link", onClick: () => this.props.app.redirect("register") }, "\u6CE8\u518C"))))));
        }
    }
    exports.default = LoginPage;
});
